// 创建一个路由器并暴露出去

// 1.引入createRouter
import {
  createRouter,
  createWebHashHistory,
  createWebHistory,
} from "vue-router";
// 引入路由路由组件
import About from "@/pages/About.vue";
import Home from "@/pages/Home.vue";
import News from "@/pages/News.vue";
import Detail from "@/pages/Detail.vue";

// 2.创建路由器
const router = createRouter({
  // 设置路由器的工作模式
  history: createWebHistory(), // history模式
  // history: createWebHashHistory(), // hash模式
  routes: [
    {
      name: "zhuye",
      path: "/home",
      component: Home,
    },
    {
      name: "xinwen",
      path: "/news",
      component: News,
      // 嵌套路由使用children配置项
      children: [
        {
          name: "xiangqing",
          // path: "detail",
          path: "detail/:id/:title/:content?", 
          // 声明接收params参数 ?表示可选参数
          component: Detail,
        },
      ],
    },
    {
      name: "guanyu",
      path: "/about",
      component: About,
    },
  ],
});

// 3.将路由器暴露
export default router;
